package lzw.codec.managers;

import java.util.Map;

import lzw.codec.exceptions.DecodingException;
import lzw.codec.exceptions.EncodingException;

/**
 * 
 * This class is responsibly to generate all artifacts related to the LZW (Lempel-Ziv-Welch) 
 * compression algorithm, which are: The encoded output based on the source input 
 * and the initial dictionary, and the decoded output based on the encoded input
 * and the initial dictionary.
 * 
 * @author Bruno Cartaxo
 * 
 * @since SEP 2009
 */
public abstract class LZWCodecManager {
	
	
	/**
	 * An factory method to return an implementation of this manager.
	 * @return The shared singleton instance.
	 */
	public static LZWCodecManager getInsntace() {
		return LZWCodecManagerImpl.getInsntace();
	}
	
	/**
	 * This method is responsibly to encode an input source based on the initial
	 * dictionary.
	 * 
	 * @param source The input source which will be encoded.
	 * @param dictionary The initial dictionary (only with root characters).
	 * @return The encoded output.
	 * @throws EncodingException An encoding exception will be throw when any error
	 *                           occur in the encoding process.
	 */
	public abstract String encode(String source, Map<Integer, String> initialDictionary) 
		throws EncodingException;
	
	/**
	 * This method is responsibly to decode an input encoded based on the initial
	 * dictionary.
	 * 
	 * @param encoded The encoded input which will be decoded.
	 * @param dictionary The inital dictionary (only with root code words).
	 * @return The decoded output.
	 * @throws DecodingException An decoding exception will be throw when any error
	 * 							 occur in the decoding process.
	 */
	public abstract String decode(String encoded, Map<Integer, String> initialDictionary) 
		throws DecodingException;
	
}
